/**
 * @name 权限
 */
layui.define(['larry', 'form', 'table','upload'], function(exports) {
    "use strict";
    var $ = layui.$,
    larry = layui.larry,
    form = layui.form,
    upload = layui.upload,
    table = layui.table;
    
    $.post("/backend/system/upms/role/selectRole",{},function(result){
		for (var i = 0; i < result.data.length; i++) {
			$("#roleId").append("<option value="+result.data[i]["roleId"]+">"+result.data[i]["name"]+"</option>");
		}
		form.render('select');
		selectByUserId();
		
    });
    
    function selectByUserId () {
	    	 $.post("/backend/system/upms/user/selectByUserId",{"userId":GetQueryString("userId")},function(result){
	     		$("#roleId").val(result.data["roleId"]);
	     		form.render('select');
	     		selectAdminUserByUserId();
	     });
	}
    
    function selectAdminUserByUserId() {
	    	 $.post("/backend/system/upms/user/selectAdminUserByUserId",{"userId":GetQueryString("userId")},function(result){
	     		$("#username").val(result.data["username"]);
	     		$("#realname").val(result.data["realname"]);
	     		//头像
	     		$("#userId").val(result.data["userId"]);
	     		$("#phone").val(result.data["phone"]);
	     		$("#email").val(result.data["email"]);
	     		$("#avatarSrc").attr('src',result.data["avatar"]); 
	     		$("input[name='sex'][value="+result.data["sex"]+"]").prop("checked", true);
	     		form.render('radio');
	    	 });
	}
    
    
    
   
  //监听提交
    form.on('submit(editUser)', function(data) {
    		$.post("/backend/system/upms/user/updataAdminUser",data.field,function(result){
    			if(result.status != 200){
    				layer.msg(result.msg);
    			} else {
    				parent.layer.closeAll();
			}
    		});
        return false;
    });
   
 
 
    
    //文件上传
    upload.render({
    	  elem: '#picture',
    	  url: '/Upload/layuiUpload', //必填项
    	  method: 'post',  //可选项。HTTP类型，默认post
    	  accept:'images',
    	  done: function(res, index, upload){
    		console.log();
    		$("#avatar").val(res.data["fullPath"]);
    		$("#avatarSrc").attr('src',res.data["downloadUrl"]); 
    	  }
    	});
    
    
  
    
    exports('mypanel', {});
});